from django.db import models
from django.contrib.auth import get_user_model

User = get_user_model()

class Article(models.Model):
    ARTICLE_TYPES = (
        ('admission', '院校招生信息'),
        ('major', '专业介绍'),
        ('exam', '考试大纲'),
        ('book', '参考书目'),
    )
    
    type = models.CharField('类型', max_length=20, choices=ARTICLE_TYPES)
    title = models.CharField('标题', max_length=100)
    content = models.TextField('内容')
    author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='作者')
    created_at = models.DateTimeField('创建时间', auto_now_add=True)
    updated_at = models.DateTimeField('更新时间', auto_now=True)
    views = models.PositiveIntegerField('浏览量', default=0)
    is_published = models.BooleanField('是否发布', default=True)

    class Meta:
        verbose_name = '文章'
        verbose_name_plural = '文章'
        ordering = ['-created_at']

    def __str__(self):
        return self.title
